home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWTaskG / Include / FWPriTas.h next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  5.0 KB  |  162 lines  |  [TEXT/MPS ]

  1. #ifndef FWPRITAS_H
  2. #define FWPRITAS_H
  3. //========================================================================================
  4. //
  5. //    File:                FWPriTas.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/25/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #include <stddef.h>
  15.  
  16. #if defined(FW_BUILD_MAC) && !defined(FW_HAS_INSTANCE_DATA)
  17. #define FW_HAS_INSTANCE_DATA
  18. #endif
  19.  
  20. //========================================================================================
  21. // STRUCT FW_SPrivTaskGlobalsHeader
  22. //
  23. //    By convention, the task globals area has this header structure.
  24. //========================================================================================
  25.  
  26. struct FW_SPrivTaskGlobalsHeader
  27. {
  28.     short    gPrivTaskGlobalsSize;
  29.     void*     gThisBlock;
  30. };
  31.  
  32. //========================================================================================
  33. // CLASS FW_CPrivTaskGlobals
  34. //    An interface for per task globals.  A set of DLLs and an application can share task
  35. //    specific global data using this interface.
  36. //========================================================================================
  37.  
  38. class FW_CPrivTaskGlobals
  39. {
  40.  
  41. public:
  42.  
  43.     static void*    GetTaskGlobals();
  44.         // Get a pointer into the globals block
  45.  
  46.     static void*    GetTaskGlobals(unsigned short offset);
  47.         // Get a pointer into the globals block, positioned at offset from start of block
  48.  
  49.     static void        Initialize();
  50.         // Initialize task data for this component.
  51.         
  52.     static void        Terminate();
  53.         // Terminate (cleanup) task data for this component.
  54.  
  55.     static FW_SPrivTaskGlobalsHeader&    GetTaskGlobalsHeader();
  56.         // Terminate (cleanup) task data for this component.
  57.     
  58.     static void        UsesTaskGlobalData(unsigned short offset, unsigned short size);
  59.         // Inform task globals mechanism that component uses specified data slots
  60.         // This function should be called before calling GetTaskGlobals(offset),
  61.         // but only if offset+size > kDefaultGlobalsBlockSize.
  62.         
  63. private:
  64.  
  65.     static void*        PrivGetTaskGlobals();
  66.         // Get the pointer to the task globals block.
  67.         // Pointer may be NULL, indicating globals aren't initialized.
  68.         
  69.     static void            PrivSetTaskGlobals(void* globals);
  70.         // Set the pointer to the task globals block.
  71.         // Client is responsible for disposing the previous block, if any.
  72.  
  73.     static void*        AllocateTaskGlobals();
  74.         // Get the pointer to the task globals block.
  75.         // Pointer may be NULL, indicating globals aren't initialized.
  76.         
  77.     static void            ResizeTaskGlobals(unsigned short size);
  78.         // Resize the task globals block.
  79.         
  80.     static void            FatalExit();
  81.         // Exit application due to failure to allocate task globals block.
  82.         
  83.     enum
  84.     {
  85.         kTaskGlobalsHeaderOffset = 0,
  86.         kDefaultGlobalsBlockSize = 256
  87.     };
  88.  
  89.     FW_CPrivTaskGlobals();
  90.         // This class should never be instantiated -- all members are static
  91.  
  92. #ifdef FW_HAS_INSTANCE_DATA
  93.     static void*            gTaskGlobalData;
  94. #endif
  95. };
  96.  
  97. #ifdef FW_BUILD_WIN
  98. //----------------------------------------------------------------------------------------
  99. //    Extern routines written in assembler
  100. //----------------------------------------------------------------------------------------
  101. #ifdef FW_BUILD_WIN16
  102. extern "C"
  103. {
  104. #endif
  105.     void* FW_PrivWinGetTaskGlobals();
  106.     void FW_PrivWinSetTaskGlobals(void* p);
  107. #ifdef FW_BUILD_WIN16
  108. };
  109. #endif
  110. #endif
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    FW_CPrivTaskGlobals::PrivGetTaskGlobals
  114. //----------------------------------------------------------------------------------------
  115.  
  116. inline void* FW_CPrivTaskGlobals::PrivGetTaskGlobals()
  117. {
  118. #if defined(FW_HAS_INSTANCE_DATA)
  119.     return gTaskGlobalData;
  120. #elif defined(FW_BUILD_WIN)
  121.     return FW_PrivWinGetTaskGlobals();
  122. #else
  123.     Error;    // Unknown configuration for task global data
  124. #endif
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    FW_CPrivTaskGlobals::PrivSetTaskGlobals
  129. //----------------------------------------------------------------------------------------
  130.  
  131. inline void    FW_CPrivTaskGlobals::PrivSetTaskGlobals(void* globals)
  132. {
  133. #if defined(FW_HAS_INSTANCE_DATA)
  134.     gTaskGlobalData = globals;
  135. #elif defined(FW_BUILD_WIN)
  136.     FW_PrivWinSetTaskGlobals(globals);
  137. #else
  138.     Error;    // Unknown configuration for task global data
  139. #endif
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CPrivTaskGlobals::GetTaskGlobals
  144. //----------------------------------------------------------------------------------------
  145.  
  146. inline void* FW_CPrivTaskGlobals::GetTaskGlobals(unsigned short offset)
  147. {
  148.     return (void*) ((char*)GetTaskGlobals()+offset);
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_CPrivTaskGlobals::GetTaskGlobalsHeader
  153. //----------------------------------------------------------------------------------------
  154.  
  155. inline FW_SPrivTaskGlobalsHeader& FW_CPrivTaskGlobals::GetTaskGlobalsHeader()
  156. {
  157.     return *((FW_SPrivTaskGlobalsHeader*)GetTaskGlobals(kTaskGlobalsHeaderOffset));
  158. }
  159.  
  160. #endif
  161.  
  162.